#include <iostream>
#include <vector>
#include <utility>
#include <cmath>

// 定义类型别名
using Point = std::pair<double, double>;
using Path = std::vector<Point>;

class ZigzagPathPlanner {
private:
    double left_top_x;
    double left_top_y;
    double width;
    double height;
    int num_drones;
    double spacing;
    double gap;

public:
    ZigzagPathPlanner(double lt_x = 0, double lt_y = 0, double w = 0, double h = 0, int drones = 1, double sp = 0, double g = 0)
        : left_top_x(lt_x), left_top_y(lt_y), width(w), height(h), num_drones(drones), spacing(sp), gap(g) {}

    Path generateZigzagPath(double x_min, double x_max, double y_min, double y_max) {
        Path path;
        for (double x = x_min; x < x_max; x += spacing) {
            if (static_cast<int>((x - x_min) / spacing) % 2 == 0) {
                path.emplace_back(x, y_min);
                path.emplace_back(x, y_max);
            } else {
                path.emplace_back(x, y_max);
                path.emplace_back(x, y_min);
            }
        }
        return path;
    }

    std::vector<Path> generatePaths() {
        std::vector<Path> all_paths;
        double sub_height = height / num_drones;

        for (int i = 0; i < num_drones; ++i) {
            double y_min = left_top_y - (i + 1) * sub_height + gap / 2;
            double y_max = left_top_y - i * sub_height - gap / 2;

            Path path = generateZigzagPath(left_top_x, left_top_x + width, y_min, y_max);
            all_paths.push_back(path);
        }
        return all_paths;
    }

    void printPaths(const std::vector<Path>& paths) {
        for (size_t i = 0; i < paths.size(); ++i) {
            std::cout << "Drone " << i + 1 << " Path:\n";
            for (const auto& point : paths[i]) {

                std::cout << "(" << point.first << ", " << point.second << ")\n";
            }
            std::cout << "\n";
        }
    }
    void reset_params(double left_top_xs, double left_top_ys,  double w, double h, int drones, double sp, double g){
        width = w;
        height = h;
        num_drones = drones;
        spacing = sp;
        gap = g;
        left_top_x = left_top_xs;
        left_top_y = left_top_ys;
    }
};